package com.jeff.tianti.cms.dao;

import com.jeff.tianti.common.dao.CustomBaseSqlDaoImpl;
import com.jeff.tianti.common.entity.PageModel;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.jeff.tianti.cms.entity.CnaaApplyFor;
import com.jeff.tianti.cms.dto.CnaaApplyForQueryDTO;
import org.apache.commons.lang3.StringUtils;

/**
 * @author xujianfang
 * @desc CnaaApplyForDaoImpl��
 * @date 2019-07-05
 */

public class CnaaApplyForDaoImpl extends CustomBaseSqlDaoImpl implements CnaaApplyForDaoCustom {

    public PageModel<CnaaApplyFor> queryCnaaApplyForPage(CnaaApplyForQueryDTO cnaaApplyForQueryDTO) {
        Map<String, Object> map = new HashMap<String, Object>();
        StringBuilder hql = new StringBuilder();
        hql.append("select t from CnaaApplyFor t where 1= 1");
        if (cnaaApplyForQueryDTO != null) {
            String auditFlag = cnaaApplyForQueryDTO.getAuditFlag();
            if (StringUtils.isNotBlank(auditFlag) && !"-1".equals(auditFlag)) {
                hql.append(" and t.auditFlag = :auditFlag ");
                map.put("auditFlag", auditFlag);
            }
            String level = cnaaApplyForQueryDTO.getLevel();
            if (StringUtils.isNotBlank(level) && !"-1".equals(level)) {
                hql.append(" and t.level = :level ");
                map.put("level", level);
            }
        }
        hql.append(" order by t.sort desc,t.createDate desc ");

        return this.queryForPageWithParams(hql.toString(), map, cnaaApplyForQueryDTO.getCurrentPage(), cnaaApplyForQueryDTO.getPageSize());
    }

    public List<CnaaApplyFor> queryCnaaApplyForList(CnaaApplyForQueryDTO cnaaApplyForQueryDTO) {
        Map<String, Object> map = new HashMap<String, Object>();
        StringBuilder hql = new StringBuilder();
        hql.append("select t from CnaaApplyFor t ");
        return this.queryByMapParams(hql.toString(), map);
    }



}